package org.lonetree.tc.core;

import org.lonetree.tc.core.id.IdentifiableItem;
import org.lonetree.tc.core.id.InternalIdentifiableItem;
import org.lonetree.tc.core.id.NumericalId;

/**
 * JAVADOC Comment
 *
 * @author xeon
 *
 */
public abstract class Comment extends InternalIdentifiableItem{
	
	private IdentifiableItem parentItem;
	private String comment;
	private boolean flagged;
	private User user;
	
	protected Comment(NumericalId id, IdentifiableItem parentItem, User user, String comment, boolean flagged){
		super(id);
		
		if(parentItem == null)
			throw new NullPointerException("parentItem cannot be null");
		
		if(user == null)
			throw new NullPointerException("user cannot be null");
		
		if(comment == null)
			throw new NullPointerException("comment cannot be null");
		if(comment.trim().equals(""))
			throw new NullPointerException("comment cannot be empty");
		
		this.parentItem = parentItem;
		this.comment = comment.trim();
		this.flagged = flagged;
		this.user = user;
	}
	
	protected final NumericalId getNumericalId(){
		return (NumericalId)getIdentifier();
	}
	
	protected IdentifiableItem getParentItem(){
		return parentItem;
	}
	
	/**
	 * JAVADOC Comment.getDescription()
	 *
	 * @return
	 */
	public String getComment(){
		return comment;
	}
	
	/**
	 * JAVADOC Comment.isFlagged()
	 *
	 * @return
	 */
	public boolean isFlagged(){
		return flagged;
	}
	
	/**
	 * JAVADOC Comment.setFlagged()
	 *
	 * @param flagged
	 */
	public void setFlagged(boolean flagged){
		this.flagged = flagged;
	}
	
	/**
	 * JAVADOC Comment.getUser()
	 *
	 * @return
	 */
	public User getUser(){
		return user;
	}
}
